@extends('admin.base')
@section('title', '子产品列表')
@section('content')
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/type/index')}}" style="cursor:pointer;" ><cite>商品列表</cite></a>;
            </span>
            </div>
        </fieldset>
        <div class="layui-card-header">
            <div>
        <span class="pull-left">
          <div class="layui-form">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">关键字</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="sub_keywords" name="keywords" value="{{ isset($request->keywords) ? $request->keywords : '' }}"  placeholder="请输入商品ID">
                </div>
                <label class="layui-form-label">图片</label>
                <div class="layui-input-inline">
                    <select name="state" lay-verify="required">
                        <option value="0">请选择</option>
                        <option value="1" @if($request->state == 1)selected @endif>无</option>
                        <option value="2" @if($request->state == 2)selected @endif>全部</option>

                    </select>
                </div>
                  <label class="layui-form-label" style="width:100px">库存不足</label>
                  <div class="layui-input-inline" style="width:130px">
                    <select name="sub_num" lay-verify="required">
                        <option value="0">请选择</option>
                        <option value="1" @if($request->num == 1)selected @endif>是</option>
                        <option value="2" @if($request->num == 2)selected @endif>否</option>
                    </select>
                      </div>
                  <label class="layui-form-label" style="width:100px">是否删除</label>
                <div class="layui-input-inline" style="width:130px">
                    <select name="sub_g_state" lay-verify="required">
                        <option value="0">请选择</option>
                        <option value="1" @if($request->g_state == 1)selected @endif>是</option>
                        <option value="2" @if($request->g_state == 2)selected @endif>否</option>
                    </select>
                </div>

              </div>
            </div>
          </div>
        </span>
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="selectsub" style="margin-top:-10px">搜索</button>
        </div>

            {{--<span class="pull-right">--}}
                {{--<button class="layui-btn layui-btn-sm" onclick="active('{{url('admin/shop/add_q')}}','','添加问答','800px','600px');" >--}}
                    {{--<i class="layui-icon">&#xe608;</i> 添加问答--}}
                {{--</button>--}}
            {{--</span>--}}
            </div>
        </div>

        <div class="layui-card-body">
            <style>
                table tr td.tc,table tr th.tc {
                    text-align: center;
                    cursor:default;
                }
            </style>
            <table class="layui-table" lay-even lay-size="">
                <colgroup>
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                </colgroup>
                <thead>
                <tr>
                    <th class="tc">主商品ID</th>
                    <th class="tc">货源ID</th>
                    <th class="tc">商品名称</th>
                    <th class="tc">货源商品名称</th>
                    <th class="tc">规格</th>
                    <th class="tc">图片</th>
                    <th class="tc">库存</th>
                    <th class="tc">销售价</th>
                    <th class="tc">货源-销售价</th>
                    <th class="tc">主产品状态</th>
                    <th class="tc">创建时间</th>
                    <th class="tc">操作</th>
                </tr>
                <tbody>
                @if($list->isEmpty())
                    <tr>
                        <td colspan="11" class="tc">暂无数据</td>
                    </tr>
                @else
                    @foreach ($list as $v)
                        <tr>
                            <td class="tc">{{$v->gid}}</td>
                            <td class="tc"><a href="javascript:void(0);"
                                              onclick="sorts_name('{{$v->id}}','{{$v->store_id}}')">
                                    {{$v->store_id}}</a></td>

                            <td class="tc">{{$v->gname}}</td>
                            <td class="tc">{{$v->sname}}</td>
                            <td class="tc">{{ $v->attr }}</td>
                            <td class="tc">@if($v['picname'])<img onclick="active('{{url('admin/sku/edit_skupic?keywords='.request()->keywrds.'&state='.request()->state.'&page='.request()->page)}}','{{$v->id}}','编辑主图')" name="picname" src="{{$v->picname}}" height="100px" style="cursor:pointer">
                                           @else <a href='javascript:void(0);' onclick="active('{{url('admin/sku/edit_skupic')}}','{{$v->id}}','编辑主图')">无</a>
                                               @endif
                            </td>
                            <td class="tc">{{$v->sum}}</td>
                            <td class="tc">{{$v->sell_price}}</td>
                            <td class="tc">{{$v->sprice}}</td>
                            <td class="tc">{{$v->mstate}}</td>
                            <td class="tc">{{ $v->created_at }}</td>
                        <td class="tc">
                            <div class="layui-btn-group" >
                                {{--<button class="layui-btn layui-btn-sm" onclick="active('{{url('admin/shop/edit_q')}}','{{$v->id}}','编辑','800px','600px');" >编辑</button>--}}
                                <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="del('{{url('admin/shop/son_delete')}}','{{$v->id}}');" >删除</button>
                            </div>
                        </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                </thead>
            </table>
            <!-- 分页 -->
            <div class="sabrosus" >{{ $page }}</div>
            <form>
                <div>
                    第&nbsp;<input type="" name="page" value="{{$pages}}" style="width:50px;border:1px solid #ddd;line-height:70px;text-align:center;height:30px;border-radius:1px">&nbsp;页
                    &nbsp;&nbsp;&nbsp;&nbsp;<button class="layui-btn layui-btn-sm" lay-submit lay-filter="selectsub">跳转</button>
                </div>
            </form>
        <!-- {{$list->total()}} -->
        </div>

    </div>
@endsection
@section('js')
    <script>
        layui.use('form', function(){
            var form = layui.form;

            //搜索
            form.on('submit(selectsub)', function(data){
                let keywords = $('#sub_keywords').val();//关键字
                var page = $("input[name=page]").val();
                var state = $("select[name=state]").val();
                var num = $("select[name=sub_num]").val();
                var g_state = $("select[name=sub_g_state]").val();

                location.href = "{{url('admin/shop/son_list')}}"+"?keywords="+keywords+'&page='+page+'&state='+state+'&num='+num+'&g_state='+g_state;
                return false;
            });

        });

        function sorts_name(id, name) {
            layer.prompt({
                formType: 3,
                value: name,
                title: '编辑'
            }, function (value, index, elem) {
                var index = layer.load();
                $.post("/admin/shop/son_update_id", {
                    id: id,
                    store_id: value,
                    _token: "{{csrf_token()}}"
                }, function (data) {
                    layer.close(index);
                    layer.msg(data.msg);
                    if (data.code == 1) {
                        location.reload();
                    }

                })
            });
        }
    </script>
@endsection